<?php
//provide session function
if (! function_exists ( "create_app_session" )) {
	function create_app_session($sess) {
		global $cfg_opts;
		if ($sess != null) {
			return $sess;
		}
		// load configuration form config.php
		$options = array ();
		if (defined ( "SESSION_NAME" )) {
			$options ['session_name'] = SESSION_NAME;
		}
		if (defined ( "SESSION_EXPIRE" ) && is_numeric ( SESSION_EXPIRE )) {
			$options ["session_expire"] = SESSION_EXPIRE;
		}
		if (defined ( "SESSION_PATH" )) {
			$options ["session_path"] = SESSION_PATH;
		}
		
		if (rqset ( '_sess_id' )) { //if set sess_id then tell phpsession to load the _sess_id session
			$sid = rqst ( "_sess_id" );
			if (! empty ( $sid )) {
				define ( "APP_SESSION_ID", $sid );
			}
		}
		return new PhpSession ( $options );
	}
}
bind ( 'get_session_driver', 'create_app_session', 100, 1 );